#include <fstream>
#include <string>
#include <iostream>
#include <cstdlib>
#if _WIN32
#include "XGetOpt.h"
#else
#include <unistd.h>
#endif

#define MAXLINELEN 10000

using namespace std;

void usage()
{
	cout <<"Fastq Convert to Fasta Program Usage:" <<endl;
	cout <<"-i inputName \tInput FASTQ file." <<endl;
	cout <<"-o outputName \tOutput FASTA file." <<endl;
	cout <<"-h \t Show this help information." <<endl;
}

int main(int argc, char* argv[])
{
	string src;
	string dst;
	int ch;
	while((ch = getopt(argc, argv, "i:o:h"))!= -1)
	{
		switch(ch)
		{
		case 'i':
			src = optarg;
			break;
		case 'o':
			dst = optarg;
			break;
		case 'h':
			usage();
			return 0;
		case '?':
			// getopt already put error message
		default:
			usage();
			abort(); //return val = 134?
		}
	}

	fstream fpsrc(src.c_str(), ios::in);
	fstream fpdst(dst.c_str(), ios::out);
	if(!fpsrc.is_open() || !fpdst.is_open())
	{
		cerr <<"open file error"<<endl;
		exit(1);
	}
	char line[MAXLINELEN];
	while(!fpsrc.eof())
	{
		fpsrc.getline(line, MAXLINELEN);
		line[0] = '>';
		fpdst << line << endl;

		fpsrc.getline(line, MAXLINELEN);
		fpdst << line << endl;

		fpsrc.getline(line, MAXLINELEN);
		fpsrc.getline(line, MAXLINELEN);
	}
	fpsrc.close();
	fpdst.close();
	return 0;
}